/**
 * 公用的全局数据管理
 */

let number = 0;  //编号，用于区分数据实例
 
const targetNumberMap = {};

const numberSymbol = Symbol('number');

export default class GlobalVar{
    constructor(){
        this.target = {};
        this[numberSymbol] = ++ number;
        targetNumberMap[this[numberSymbol]] = this;
    }
    set(key,value){
        this.target[key] = value;
        return key;
    }
    get(key){
        return this.target[key];
    }
    getNumber(){
        this[numberSymbol];
    }
    destroy(){
        delete targetNumberMap[this[numberSymbol]]; 
    }
}

/** 获取实例 */
export default function getInstance(number){
    return targetNumberMap[number]; 
}

/** 销毁实例 */
export default function destroyInstance(number){
    delete targetNumberMap[number]; 
}
